#include "mainscence.h"
#include "ui_mainscence.h"


#include <QDebug>
#include <QFileDialog>
#include <QPixmap>
#include <QMessageBox>

MainScence::MainScence(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainScence)
{
    ui->setupUi(this);
    m_engp = new BdFaceEngine();
    qDebug() << QSslSocket::sslLibraryBuildVersionString();
}

MainScence::~MainScence()
{
    delete ui;
}

void MainScence::register_user()
{
    //尝试注册
    QString filepath = ui->filepathEdit->text();

    QString user_info = ui->infoEdit->text();
    int user_id = ui->idEdit->text().toInt();
    int ret = m_engp->register_face(filepath, user_info,user_id);
    if(ret > 0)
    {
        qDebug() <<"注册成功";
        QMessageBox::information(this, "注册提示","注册成功");
    }
    else
    {
        qDebug() <<"注册失败";
        QMessageBox::information(this, "注册提示","注册失败");
    }
}



void MainScence::query_user()
{
    QString filepath = ui->filepathEdit->text();
    int ret = m_engp->search_face(filepath);
    if(ret > 0)
    {
        qDebug() <<"查询成功";
        QMessageBox::information(this, "查询提示","查询成功");
    }
    else
    {
        qDebug() <<"查询失败";
        QMessageBox::information(this, "查询提示","查询失败");
    }
}


void MainScence::on_openBtn_clicked()
{
    //1. 如何弹出文件搜索框呢？
    QString file_name;
    file_name = QFileDialog::getOpenFileName(this, "文件栏");

    //显示路径
    ui->filepathEdit->setText(file_name);

    //显示图像
    QPixmap avatar(file_name);
    avatar = avatar.scaledToWidth(ui->avatarLbl->width());
    ui->avatarLbl->setPixmap(avatar);

}

void MainScence::on_regBtn_clicked()
{
    register_user();
}






void MainScence::on_queryBtn_clicked()
{
    query_user();
}
